# vim: filetype=yaml sw=2
version: '[% c("abbrev") %]'
git_url: https://git.torproject.org/pluggable-transports/snowflake.git
git_hash: d11e55aabe3753dbddca18ae084c80ad09e282d3
filename: '[% project %]-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.gz'

build: '[% c("projects/go/var/build_go_lib") %]'

var:
  container:
    use_container: 1
  go_lib: git.torproject.org/pluggable-transports/snowflake.git
  go_lib_install:
    - git.torproject.org/pluggable-transports/snowflake.git/client
  go_lib_deps:
    - go-webrtc
    - uniuri
    - goptlib
  go_lib_ldflags: '-s'
  build_go_lib_pre: |
    [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
    [% IF c("var/linux") %]
      tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
      export PATH="/var/tmp/dist/binutils/bin:$PATH"
      # The go-webrtc package sets _GLIBCXX_USE_CXX11_ABI=0 for compatibility with
      # the prebuilt libwebrtc-magic.a libraries. Since we build our own
      # libwebrtc-magic.a with the C++11 ABI, we have to undo that setting here,
      # using CGO_CXXFLAGS.
      export CGO_CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=1"
    [% END -%]
    [% IF c("var/osx") %]
      export CGO_ENABLED=1
      export CGO_CFLAGS="[% c("var/FLAGS") %] -mmacosx-version-min=10.7"
      export CGO_CXXFLAGS="[% c("var/FLAGS") %] -stdlib=libc++ -mmacosx-version-min=10.7"
      export CGO_LDFLAGS="[% c("var/FLAGS") %] -stdlib=libc++ -mmacosx-version-min=10.7"
      export CC="$clangdir/bin/clang"
      export CXX="$clangdir/bin/clang++"
      # Without faketime, snowflake-client would contain the timestamp of the
      # temporary client.a file created during "go build".
      # The -tmpdir flag overrides what would otherwise be a randomly generated
      # path, /tmp/go-link-RANDOMNUM/go.o.
      mkdir -p /var/tmp/go-link.tmpdir
    [% END %]
  go_lib_no_output: 1
  build_go_lib_post: |
    [% c("var/set_PTDIR_DOCSDIR") -%]
    mkdir -p $PTDIR $DOCSDIR

    cp -a "$GOTARGETBIN/client[% IF c('var/windows') %].exe[% END %]" $PTDIR/snowflake-client[% IF c("var/windows") %].exe[% END %]

    cd "$GOPATH/src/git.torproject.org/pluggable-transports/snowflake.git/"
    cp -a README.md LICENSE $DOCSDIR

    cd $distdir
    [% c('tar', {
            tar_src => [ '.' ],
            tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
        }) %]

targets:
  linux-i686:
    var:
      arch_deps:
        - pkg-config
        - libx11-dev:i386
  linux-x86_64:
    var:
      arch_deps:
        - pkg-config
        - libx11-dev
  osx-x86_64:
    var:
      arch_deps:
        - faketime
      go_lib_install_env: '[% c("var/faketime") %]'
      go_lib_ldflags: '-s -tmpdir /var/tmp/go-link.tmpdir'

input_files:
  - project: container-image
  - name: go
    project: go
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
  - name: binutils
    project: binutils
    enable: '[% c("var/linux") %]'
  - name: go-webrtc
    project: go-webrtc
  - name: uniuri
    project: uniuri
  - name: goptlib
    project: goptlib
